package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.mapper.AddressMapper;
import cn.tedu.egmvc1.pojo.dto.InsertAddressDTO;
import cn.tedu.egmvc1.pojo.entity.Address;
import jdk.nashorn.internal.runtime.ListAdapter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @RequestMapping("insert")
    public String insertAddress(InsertAddressDTO insertAddressDTO){
        Address address = new Address();
        BeanUtils.copyProperties(insertAddressDTO,address);
        addressMapper.insertAddress(address);
        return "添加成功";
    }

    @RequestMapping("select")
    public List<Address> selectList(){
        return addressMapper.selectList();
    }

    @RequestMapping("delete")
    public String deleteAddress(int id){
        addressMapper.deleteAddress(id);
        return "删除成功";
    }

    @RequestMapping("update")
    public String updateAddress(Address address){
        addressMapper.updateAddress(address);
        return "修改成功";
    }
}
